@extends('layouts.main')

@section('title', '预估开票金额_年份')

@section('content')
<h3>@yield('title')</h3>
<div class="btn-group" role="group">
  	<a href="{{ action('BusinessData\PredictInvoiceYearController@create') }}" class="btn btn-primary">添加预估数据</a>
</div>

@if(session('success'))
<div class="alert alert-success" role="alert">{{ session('success') }}</div>
@endif

<div class="clearfix"></div>
<hr>

<form class="form-inline pull-right" method="get" action="{{ action('BusinessData\PredictInvoiceYearController@index') }}">
    
    <div class="form-group">
        <label for="year">年份</label>
        <select class="form-control" id="year" name="year">
            <option>请选择年份</option>
            @for($i = 2020; $i <= 2030; $i++)
            <option value="{{ $i }}" @if(request()->year == $i) selected @endif>{{ $i }}</option>
            @endfor
          </select>
    </div>

    <button type="submit" name="search" value="search" class="btn btn-primary">查询</button>

</form>

<div class="clearfix"></div>
<hr>

<table class="table table-bordered table-striped table-hover">
    <tr>
		<th>id</td>
		<th>年度</td>
		<th>大区</td>
		<th>预估金额</td>
		<th>操作</td>
    </tr>
  @forelse($models as $model)
	<tr>
		<td>{{ $model->id }}</td>
		<td>{{ $model->year }}</td>
		<td>{{ $model->sales_region->code_desc }}</td>
		<td>{{ number_format($model->amount, 2) }}</td>
		<td>
			<a href="{{ action('BusinessData\PredictInvoiceYearController@edit', $model) }}" class="btn btn-warning btn-sm">编辑</a>
			<button name="delete" value="{{ $model->id }}" class="btn btn-danger btn-sm">删除</button>
		</td>
	</tr>
  @empty
  	<tr><td>暂无数据</td></tr>
  @endforelse
    <tr>
        <th>合计</td>
        <th></td>
        <th></td>
        <th>{{ number_format($total_amount, 2) }}</td>
        <th></td>
    </tr>
</table>
{{ $models->appends([
    'year' => request()->year,
    ])->links() }}
<script>
      $(document).ready(function(){
        $("button[name=delete]").click(function(){
            var that = $(this);
            var id = that.attr("value");
            $.post("/business_data/predict_invoice_year/" + id, {
                '_method': 'DELETE',
                '_token': '{{ csrf_token() }}',
            }, function(data){
                switch(data.status){
                    case 0:
                        that.parent().parent('tr').remove();
                        alert("删除信息成功！");
                        break;
                }
            });
        });
    });
</script>
@endsection